//
//  ViewController.m
//  iOSUILibDemo1
//
//  Created by fangjs on 16/1/13.
//  Copyright © 2016年 fangjs. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *MyTableView;
@property NSMutableArray *controls;

@end

@implementation ViewController

typedef NS_ENUM(NSUInteger,UIViewController_IS) {
    UIViewController_IS_Button,
    UIViewController_IS_ButtonFloating,
    UIViewController_IS_TableViewCell,
    UIViewController_IS_ProgressBar,
    UIViewController_IS_TextField,
    UIViewController_IS_Switch,
    UIViewController_IS_DatePicker,
    UIViewController_IS_DatePickerDialog,
    UIViewController_IS_CollectionViewCell,
    UIViewController_IS_TabBar,
    UIViewController_IS_TimePickerDialog,
    UIViewController_IS_TabBarViewController,
    UIViewController_IS_Snackbar,
    UIViewController_IS_Toast,
    UIViewController_IS_Slider,
    UIViewController_IS_Count
};

static NSArray *controlsName;

+ (NSArray *)controlsName {
    if (!controlsName)
        controlsName = [NSArray
                        arrayWithObjects:@"Button", @"ButtonFloating", @"TableView Cell",
                        @"Progress Bar", @"Text Field", @"Switch",
                        @"Date Picker", @"Date Picker Dialog",
                        @"Collection View Cell", @"Tab Bar",
                        @"Time Picker Dialog", @"Tab Bar View Controller",
                        @"Snackbar", @"Toast", @"Slider", nil];
    
    return controlsName;
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationItem.title = @"控件集合";
    
    
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"collect" ofType:@"plist"];
//    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
//    NSLog(@"dict = %@",dict);
    
//    [dict setObject:@"22" forKey:@"age"];
//    [dict setObject:@"wang" forKey:@"name"];
//    NSLog(@"%@",dict);
//    BOOL ok =  [dict writeToFile:path atomically:YES];
//    NSLog(@"ok = %d",ok);
//    NSLog(@"%@",dict);
//    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:path];
//    NSLog(@"%@",dic);
//    NSLog(@"path = %@",path);

    
    //读取plist文件在程序文件夹中的文件，并且要注意，程序文件的文件只能读不能写，只能在程序沙盒之中；
//    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"collect" ofType:@"plist"];
//    NSLog(@"这是plist文件的路径%@", plistPath);
//    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
//    NSLog(@"这是plist文件的内容%@", data);
    
    
//    //添加数据说明，可以进行修改；
//    [data setObject:@"wangjiayu" forKey:@"name"];
//    [data setObject:@"我在东北大学" forKey:@"address"];
//    [data setObject:@"男" forKey:@"sex"];
//    //获取应用沙盒的的DOCUMENT 的路径；
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString* plistPath1 = [paths objectAtIndex:0];
//
//    //在此处设置文件的名字补全其中的路径, 注意对于文件内存的修改是在内存之中完成的，然后直接把现在的数据一次性更新，这样减少了文件的读写的次数
//    NSString *filename =[plistPath1 stringByAppendingPathComponent:@"collect.plist"];
//    NSLog(@"这是沙盒之中的路径%@", filename);
//    
//    //写入文件
//    [data writeToFile:filename atomically:YES];
//    
//    NSLog(@"证明我的数据真正得写入在其中了");
//    
//    //证明文件写入成功
//    NSMutableDictionary *afterData = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
//    NSLog(@"这是写入过数据的情况%@", afterData);
//
//    NSLog(@"程序结束");
    
  
    
    self.MyTableView.rowHeight = 44;
    for (NSString *control in [ViewController controlsName]) {
        [self insertRow:control];
    }
    [self.navigationController.navigationBar setTranslucent:NO];
    [[NSCalendarHelper mdSharedCalendar] setFirstWeekday:2];
   
}

- (void)insertRow:(NSString *)label {
    if (!self.controls) {
        self.controls = [[NSMutableArray alloc] init];
    }
    [self.controls addObject:label];
}

#pragma mark - UITableViewDataSource
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.controls.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = [self.controls objectAtIndex:indexPath.row];
    
    return cell;
}

#pragma mark - UITableViewDelegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case UIViewController_IS_Button:
            [self performSegueWithIdentifier:@"ButtonViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_ButtonFloating:
            [self performSegueWithIdentifier:@"FloatingButtonTableViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_TableViewCell:
            [self performSegueWithIdentifier:@"TabBarViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_ProgressBar:
             [self performSegueWithIdentifier:@"ProgressViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_TextField:
             [self performSegueWithIdentifier:@"TextFieldViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_Switch:
             [self performSegueWithIdentifier:@"SwitchViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_DatePicker:
             [self performSegueWithIdentifier:@"DatePickerViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_DatePickerDialog:
             [self performSegueWithIdentifier:@"DatePickerDialogControllerID" sender:nil];
            break;
            
        case UIViewController_IS_CollectionViewCell:
             [self performSegueWithIdentifier:@"CollectionViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_TabBar:
             [self performSegueWithIdentifier:@"TabBarViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_TimePickerDialog:
             [self performSegueWithIdentifier:@"TimePickerDialogViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_TabBarViewController:
            [self performSegueWithIdentifier:@"TabBarViewControllerViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_Snackbar:
             [self performSegueWithIdentifier:@"SnackBarViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_Toast:
             [self performSegueWithIdentifier:@"ToastViewControllerID" sender:nil];
            break;
            
        case UIViewController_IS_Slider:
             [self performSegueWithIdentifier:@"SliderViewControllerID" sender:nil];
            break;
            
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
